//获取弹组合并显示
var outhtml = '';
var isopenmsgblock = 0;  //短暂弹层

$(document).ready(function() {
    //
    $(document).on("click", "#tips_showsharetopid", function () {
        outjs_outshoare_div_close()
    });
});

function outjs_open(tit,sno,t)
{
    if(typeof(t) == 'undefined')t=0;
    if(t == 0)
    {
        if(outhtml == '')
        {
            outhtml = outjs_outhtml(tit,sno,t);
        }
        $('#outdivid').remove();
        $('body').append(outhtml);
    }
    else
    {
        var outhtml_t = outjs_outhtml(tit,sno,t);
        $('#outdivid').remove();
        $('body').append(outhtml_t);
    }  
}

//关闭层
function outjs_close()
{
    $('#outdivid').remove();
}

//获取弹出层的html|t=0是单钮 t=1是双键
function outjs_outhtml(tit,sno,t)
{
    if(typeof(tit) == 'undefined')tit='';
    if(typeof(sno) == 'undefined')sno='';
    if(typeof(t) == 'undefined')t=0;
    var html  = '';
    html += '';
    html += '<div class="outlayers ps" id="outdivid">';
    html += '    <div class="outlayersin pr">';
    html += '        <div class="outtipsbg o_50 ps"></div>';
    html += '        <div class="outtips ps">';
    html += '            <div class="outtipsin pr">';
    html += '               <a class="outtipsclose ps" id="outcloseid" href="###">×</a>';
    html += '               <div class="outoktit" id="outtitid">'+tit+'</div>';
    html += '               <div class="outoksno" id="outsnoid">'+sno+'</div>';
    if(t == 0)
    {
        html += '               <a class="outokbtn" id="outbtnid" href="###">确认</a>';
    }
    else
    {
        html += '               <div class="outokbtnbox" id="outokbtnid">';
        html += '                   <div class="oobb_left"><a class="outokbtn outokbtn_l" id="outbtnid" href="###">确认</a></div>';
        html += '                   <div class="oobb_right"><a class="outokbtn outokbtn_r" id="outcancelbtnid" href="###">取消</a></div>';
        html += '               </div>';
    }
    html += '           </div>';
    html += '        </div>';
    html += '    </div>';
    html += '</div>';
    return html;
}

//获取选择的弹层
function outjs_se_outhtml(t)
{
    if(typeof(t) == 'undefined')
    {
        var boxidname   = 'outseldivid';
        var closeidname = 'outselcloseid';
        var snoidname   = 'outseldivsnoid';
        var btnidname   = 'outselbtnid';
    }
    else
    {
        var boxidname   = 'outseldivid_'+t;
        var closeidname = 'outselcloseid'+t;
        var snoidname   = 'outseldivsnoid'+t;
        var btnidname   = 'outselbtnid'+t;
    }
    var html  = '';
    html += '<div class="outsellayers pf" id="'+boxidname+'">';
    html += '    <div class="outsellayersin pr">';
    html += '       <a class="outseltipsclose ps" id="'+closeidname+'" href="###">×</a>';
    html += '       <div class="outseldivsno" id="'+snoidname+'"></div>';
    html += '       <div class="outselbtnline"><a class="outselokbtn" id="'+btnidname+'" href="###">确认</a></div>';
    html += '    </div>';
    html += '</div>';
    return html;
}

function outjs_open_2(t , classname)
{
    if(typeof(t) == 'undefined')t=0;
    if(typeof(classname) == 'undefined')classname='';
    if(t == 0)
    {
        var s_div = '<div class="lotsi_txt_sno">&nbsp;</div>';
    }
    else
    {
        if(classname == '')
        {
            classname = 'lotsi_txt_ano';
        }
    }
    var outhtml = outjs_outhtml2(t , classname);
    outjs_close_2('');
    $('body').append(outhtml);
    $('body').append('<div id="lot_outbgtipsid" class="lot_outbtbg ps o_70"></div>');
}

function outjs_close_2(callback)
{
    $('#lot_outtipsid').remove();
    $('#lot_outbgtipsid').remove();
    if(callback != '')
    {
        //alert('回调');
    }
}

//显示获奖层
function outjs_open_3(n)
{
    if(typeof(n) == 'undefined')
    {
        n = 0;
    }
    else
    {
        n = parseInt(n);
    }
    if(n >= 6 || n < 1)
    {
        var classname = 'showmyprizetips_none';
    }
    else
    {
        var classname = 'showmyprizetips';
    }
    var html = '';
    html += '<div id="tips_showmyprizeid" class="'+classname+' ps">';
    html += '   <div class="tips_sp_prize_in pr">';
    html += '       <div class="tips_sp_prize ps">';
    html += '       </div>';
    html += '       <div class="tips_sp_prize_btn ps">';
    html += '           <a href="###" id="tips_next_id" class="tips_next">再来一局</a>';
    html += '       </div>';
    html += '   </div>';
    html += '</div>';
    $('#tips_showmyprizeid').remove();
    $('body').append(html);
    $('body').append('<div id="tips_showprizebgid" class="prize_outbg ps o_70"></div>');


}

//获取弹出层2html(登录错误层）
function outjs_outhtml2(t , classname)
{
    if(typeof(t) == 'undefined')t=0;
    if(typeof(classname) == 'undefined')classname='';
    if(t == 0)
    {
        var s_div = '<div class="lotsi_txt_sno">&nbsp;</div>';
    }
    else
    {
        if(classname == '')
        {
            classname = 'lotsi_txt_ano';
        }
        var s_div = '<div class="'+classname+'">&nbsp;</div>';
    }
    var html = '';
    html += '<div id="lot_outtipsid" class="loginouttips ps">\n' +
        '        <div class="loginouttipsin pr">\n' +
        '           <div class="loginouttipssd ps" id="ltsdid" style="display:none;">\n' +
        '           </div>\n' +
        '            <a href="###" class="lotsi_close ps">×</a>\n' +
        '            <div class="lotsi_txt">\n' +
        '                '+s_div+'\n' +
        '            </div>\n' +
        '            <div class="lotsi_btn">\n' +
        '                <a href="###" class="lotsi_btn_iknow">我知道了</a>\n' +
        '            </div>\n' +
        '        </div>\n' +
        '    </div>';
    return html;
}

//获取并显示短暂弹出层
function outjs_openblock(msg , t)
{
    if(typeof(msg) == 'undefined' || msg == '')
    {
        msg = '出错了〜';
    }
    if(typeof(t) == 'undefined' || t <= 300)
    {
        t = 1500;  //默认秒数
    }

    if(isopenmsgblock == 0)
    {
        var xyobj     = pub_getall_xy();
        var w         = xyobj.jq_body_w;
        var h         = xyobj.jq_body_h;
        var st        = xyobj.sr_t;  //卷去的高

        var bw        = parseInt(w * 0.95);
        var bt        = parseInt(h / 3);
        var bl        = parseInt((w - bw) / 2);
        var odiv      = '<div id="openblocknowid" class="openmsgblock pf o_75">'+msg+'</div>' ;
        $('body').append(odiv);
        $('#openblocknowid').css({'width':bw+'px','top':bt+'px','left':bl+'px'});
        isopenmsgblock = 1;
        setTimeout('outjs_hideblock()' , t);
    }
}

//临时层隐藏
function outjs_hideblock()
{
    $('#openblocknowid').animate({'opacity':0} , 800);
    setTimeout('outjs_closeblock()' , 800)
}

//临时层关闭
function outjs_closeblock()
{
    $('#openblocknowid').remove();
    isopenmsgblock = 0;
}

//显示一个开始提示层
function outjs_openblock_start(msg)
{
    var xyobj     = pub_getall_xy();
    var w         = xyobj.jq_body_w;
    var h         = xyobj.jq_body_h;
    var st        = xyobj.sr_t;  //卷去的高

    var bw        = parseInt(w * 0.6);
    var bt        = parseInt(h / 3) + st;
    var bl        = parseInt((w - bw) / 2);
    var odiv      = '<div id="openblockstartnowid" class="openstartmsgblock o_95 ps"><div class="osmb_in pr"><div class="osmb_in_b1 ps"></div>'+msg+'</div></div>' ;
    $('body').append(odiv);
    $('#openblockstartnowid').css({'width':bw+'px','left':bl+'px'});
    setTimeout('outjs_hidestartblock()' , 1800);
}

//临时层隐藏
function outjs_hidestartblock()
{
    $('#openblockstartnowid').animate({'opacity':0} , 800);
    setTimeout('outjs_closestartblock()' , 800)
}

//临时层关闭
function outjs_closestartblock()
{
    $('#openblockstartnowid').remove();
}

//显示一个waiting层
function outjs_openwaiting(t)
{
    outjs_closewaiting(); //防止重复
    if(typeof(t) == 'undefined')t=0;  //0-无背颢色，1-黑背颢色
    if(t == 1)
    {
        var classname = 'openwaitingblock_b';
    }
    else
    {
        var classname = 'openwaitingblock';
    }
    var xyobj     = pub_getall_xy();
    var w         = xyobj.jq_body_w;
    var h         = xyobj.jq_body_h;
    var odiv      = '<div id="openwaitingid" class="'+classname+' ps o_75"></div>' ;
    $('body').append(odiv);
    $('#openwaitingid').css({'width':w+'px','height':h+'px','top':'0px','left':'0px'});
    if(t == 1)
    {
        $('#openwaitingid').css({'background-color':'#000000'});
    }
}

//关闭waiting
function outjs_closewaiting()
{
    $('#openwaitingid').remove();
}

//金币飞出n枚
function outjs_outgolden_n(n)
{
    for(var i = 0 ; i < n ; i++)
    {
        var randcode  = Math.floor(Math.random()*1000+1);
        setTimeout('outjs_outgolden_now()' , randcode);
    }
}

//金币飞出效果
function outjs_outgolden_now()
{
    var randcode  = Math.floor(Math.random()*10000000+1);
    var idname    = 'out_gb_to_' + randcode;
    var odiv      = '<div id="'+idname+'" class="outgoldto ps"></div>' ;
    $('body').append(odiv);
    var tobj      = $('#' + idname);
    //居中
    var xyobj     = pub_getall_xy();
    var w         = xyobj.jq_body_w;
    var h         = xyobj.jq_body_h;
    var dw        = tobj.width();
    var l         = parseInt((w - dw)/2);
    var t         = parseInt((h - dw)/2);
    tobj.css({'top':t+'px','left':l+'px'});
    tobj.animate({'top':'50px','left':(w - 100) + 'px','width':'0.6rem','height':'0.6rem'} , 500);
    setTimeout('outjs_outgolden_remove(\''+idname+'\')' , 500);
}

//金币消失
function outjs_outgolden_remove(idname)
{
    var tobj      = $('#' + idname);
    tobj.remove();
}

//显示分享层
function outjs_outshare_div()
{
    outjs_outshoare_div_close();
    var xyobj     = pub_getall_xy();
    var w         = parseInt(xyobj.body_w);
    var h         = parseInt(xyobj.body_h);

    $('body').append('<div id="tips_showsharebgid" class="sweep_share_outbg pf o_70"></div>');
    $('body').append('<div id="tips_showsharetopid" class="sweep_share_outtop pf"></div>');
    $('#tips_showsharebgid').css({'width':w+'px','height':h+'px','top':'0px','left':'0px'});
    $('#tips_showsharetopid').css({'width':w+'px','height':h+'px','top':'0px','left':'0px'});
}

//隐藏分享层
function outjs_outshoare_div_close()
{
    $('#tips_showsharebgid').remove();
    $('#tips_showsharetopid').remove();
}

//帮助层
function outjs_open_help(t , classname)
{
    if(typeof(t) == 'undefined')t=0;
    if(typeof(classname) == 'undefined')classname='';
    if(t == 0)
    {
        var s_div = '<div class="lotsi_txt_sno">&nbsp;</div>';
    }
    else
    {
        if(classname == '')
        {
            classname = 'lotsi_txt_ano';
        }
    }
    var outhtml = outjs_outhtml2(t , classname);
    outjs_close_2('');
    $('body').append(outhtml);
    $('body').append('<div id="lot_outbgtipsid" class="lot_outbtbg pf o_70"></div>');
    var xyobj     = pub_getall_xy();
    var w         = parseInt(xyobj.body_w);
    var h         = parseInt(xyobj.body_h);
    $('#lot_outbgtipsid').css({'width':w+'px','height':h+'px'});
    $('#lot_outtipsid').removeClass("ps");
    $('#lot_outtipsid').addClass("pf");
}

//红包层
function outjs_open_redpack()
{
    var outhtml = '';
    outhtml += '' +
        '<div class="ored_box pf" >\n' +
        '    <div class="ored_box_bg pr">\n' +
        '        <div class="obb_in_bg_1 ps"><div class="obbiboxon pr">红包<div class="obbboin ps">红包已存入个人帐户</div></div></div>\n' +
        '        <div class="obb_in_bg_2 ps"><span class="obbiss">¥</span><span id="redpackmoneyid"></span></div>\n' +
        '        <a href="###" class="obb_in_bg_on ps" id="obb_in_bg_close_id">×</a>\n' +
        '    </div>\n' +
        '</div>';
    $('body').append(outhtml);
    $('body').append('<div id="lot_outbgtipsid" class="lot_outbtbg pf o_70"></div>');
    var xyobj     = pub_getall_xy();
    var w         = xyobj.jq_body_w;
    var h         = xyobj.jq_body_h;
    var w2        = $('.obbiboxon').width();
    var w4        = $('.obb_in_bg_on').width();
    var ow1       = parseInt(w*0.8);
    var oh1       = parseInt(ow1 * 0.6);
    var ol1       = parseInt((w-ow1)/2);
    var ot1       = parseInt((h - oh1)*0.5);
    var ow2       = parseInt(w*0.7);
    var oh2       = parseInt(ow2 * 0.4);
    var ol2       = parseInt((w-ow2)/2);
    var ot2       = ot1 - oh2 + 10;
    var mt3       = parseInt((oh1-w2)/2);
    $('.lot_outbtbg').css({'width':w+'px','height':h+'px'});
    $('.ored_box').css({'width':w+'px','height':h+'px'});
    $('.ored_box_bg').css({'width':w+'px','height':h+'px'});
    $('.obb_in_bg_1').css({'width':ow1+'px','height':oh1+'px','line-height':oh1+'px','left':ol1+'px','top':ot1+'px'});
    $('.obb_in_bg_2').css({'width':ow2+'px','height':oh2+'px','line-height':oh2+'px','left':ol2+'px','top':ot2+'px'});
    $('.obbiboxon').css({'margin-top':mt3+ 'px'});
    $('.obb_in_bg_on').css({'top':parseInt(ot1 - w4 / 3)+'px','left':parseInt(ow1+ol1- w4 / 3 * 2)+'px'});
}

